package com.example.task.config;


import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author Feri
 * @date 2021/12/27 11:44
 * @description:TODO
 */
@Configuration //标记这是配置类，beans
@EnableSwagger2 //启用Swagger
public class SwaggerConfig {
    /**
     * 构建文档的基本信息
     */
    public ApiInfo createApi(){
        return new ApiInfoBuilder().description("xxxx项目的接口在线文档,可以对接口进行测试等操作")
                .title("xxx项目的接口文档").contact(new Contact("Java2112","http://www.qfedu.com","xingfei_work@163.com"))
                .version("1.0.0").build();
    }

    /**
     * 就是ioc创建实例 修饰方法 方法必须返回对象
     */
    @Bean
    public Docket createDocket(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(createApi())
                .select().apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .build();
    }

}
